package com.yc.chatroom.ui.server;

import java.util.concurrent.CompletableFuture;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import com.yc.chatroom.server.ServerManager;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;


@SpringBootApplication
@ComponentScan(basePackages = {"com.yc.*"})
@EnableJpaRepositories("com.yc.chatroom.server.dao")//否则无法扫描Repository
@EntityScan("com.yc.chatroom.server.pojo.po")//否则无法扫描PO
public class ChatRoomServer {
	private static final Log log = LogFactory.get();
	protected static ConfigurableApplicationContext applicationContext;

	public static void main(String[] args) {
//		CompletableFuture.supplyAsync(() -> applicationContext = SpringApplication.run(ChatRoomServer.class, args))
//		.whenComplete((ctx, throwable) -> {
//			if (throwable != null) {
//				System.out.println("Failed to load spring application context: ");
//			} else {
//				//获取加载的bean
//				System.out.println("------bean-----");
//				MainServer mainServer = applicationContext.getBean(MainServer.class);
//				mainServer.start(8787);
//				
//			}
//		});
		
		applicationContext = SpringApplication.run(ChatRoomServer.class, args);
		log.info("-----applicationContext over------");
		ServerManager mainServer = applicationContext.getBean(ServerManager.class);
		mainServer.start(8787);
		System.out.println("------over-----");
	}
}
